package com.skywolf.chem.usercenter.controller;


import com.skywolf.chem.common.context.LoginUser;
import com.skywolf.chem.common.context.RequestContext;
import com.skywolf.chem.common.sysconfig.response.RespData;
import com.skywolf.chem.usercenter.pojo.vo.PermissionVO;
import com.skywolf.chem.usercenter.service.IPermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 系统用户和权限关系表 前端控制器
 * </p>
 *
 * @author
 * @since 2019-06-27
 */
@RestController
@RequestMapping("/usercenter/user-permission")
@Api(value = "用户权限API", description = "用户权限API")
public class UserPermissionController {

    @Autowired
    private IPermissionService permissionService;

    @GetMapping(value = "/current-user-permission")
    @ApiOperation(value = "获取系统用户权限列表")
    public RespData<List<PermissionVO>> currentUserPermission() {
        LoginUser user = RequestContext.getLoginUser();
        List<PermissionVO> voList = Collections.emptyList();
        if (user != null) {
            voList = permissionService.listUserPermissions(user.getId());
        }
        return RespData.success(voList);
    }
}
